<?php /* D:\phpStudy\PHPTutorial\WWW\laravel_blog\resources\views/admin/admin/list.blade.php */ ?>
<?php echo $__env->make('admin.public._head', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<!-- /Navbar -->
<!-- Main Container -->
<div class="main-container container-fluid">
    <!-- Page Container -->
    <div class="page-container">

        <!-- Page Sidebar -->
    <?php echo $__env->make('admin.public._left', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <!-- /Page Sidebar -->
        <!-- Page Content -->
        <div class="page-content">
            <!-- Page Breadcrumb -->
            <div class="page-breadcrumbs">
                <ul class="breadcrumb">
                    <li class="active">
                        <i class="fa fa-home"></i>&nbsp;管理员管理
                    </li>
                    <li>管理员列表</li>
                </ul>
            </div>
            <!-- /Page Breadcrumb -->
            <!-- Page Body -->
            <div class="page-body">
                <a href="<?php echo e(url('admin/admin_add')); ?>" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;管理员添加</a>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="widget">
                            <div class="widget-header">
                                <span class="widget-caption">栏目列表</span>
                                <div class="widget-buttons">
                                    <?php echo strReplace($admins->links()); ?>

                                </div>
                            </div>
                            <div class="widget-body">
                                <table class="table table-hover table-bordered">
                                    <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>用户名</th>
                                        <th>昵称</th>
                                        <th>邮箱</th>
                                        <th>权限</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php $__currentLoopData = $admins; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $vo): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td><?php echo e($vo->id); ?></td>
                                            <td><?php echo e($vo->username); ?></td>
                                            <td><?php echo e($vo->nickname); ?></td>
                                            <td><?php echo e($vo->email); ?></td>
                                            <td><?php if($vo->is_super ==1): ?>
                                                    超级管理员
                                                <?php else: ?>
                                                    普通管理员
                                                <?php endif; ?>
                                            </td>
                                            <td><?php if($vo->status == 1): ?>
                                                    正常
                                                <?php else: ?>
                                                    禁用
                                                <?php endif; ?>
                                            </td>
                                            <td>
                                                <?php if(session('admin.is_super') == 1): ?>
                                                    <?php if($vo->is_super != 1): ?>
                                                        <?php if($vo->status == 1): ?>
                                                            <a href="#" class="btn btn-warning btn-xs admin-status"
                                                               dataid="<?php echo e($vo->id); ?>" status="<?php echo e($vo->status); ?>">禁用</a>
                                                        <?php else: ?>
                                                            <a href="" class="btn btn-success btn-xs admin-status"
                                                               dataid="<?php echo e($vo->id); ?>" status="<?php echo e($vo->status); ?>">启用</a>
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                                <a href="<?php echo e(url('admin/admin_edit',['id' => $vo->id])); ?>"
                                                   class="btn btn-azure btn-xs">编辑</a>
                                                <a href="#" class="btn btn-danger btn-xs admin-del"
                                                   dataid="<?php echo e($vo->id); ?>">删除</a>

                                            </td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->
    </div>
    <!-- /Page Container -->
    <!-- Main Container -->

</div>

<?php echo $__env->make('admin.public._js', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<script>
    $('.pagination').addClass('pagination-sm');
    $('.admin-status').click(function () {
        var id = $(this).attr('dataid');
        var status = $(this).attr('status');
        if (status == 1) {
            var msg = "确定禁用吗？";
        } else {
            var msg = "确定启用吗?";
        }
        layer.confirm(msg, {
            title: '禁用管理员',
            icon: 3,
        }, function (index) {
            layer.close(index);
            $.ajax({
                url: "<?php echo e(url('admin/admin_status')); ?>",
                type: 'post',
                data: {id: id, status: status},
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 2000
                        }, function () {
                            location.href = data.url
                        })
                    } else {
                        //TODO layer.open 和layer.msg的区别和联系
                        layer.open({
                            title: '失败',
                            content: data.msg,
                            icon: 5,
                            anim: 6
                        })
                    }
                }
            });
        });
        //TODO 加上return false为什么就不刷新页面了呢？ 返回错误页面就不继续执行了
        return false;
    });
    $('.admin-del').click(
        function () {
            var id = $(this).attr('dataid');
            layer.confirm('确定要删除吗？', {
                title: "删除管理员",
                icon: 3,
            }, function (index) {
                layer.close(index);
                $.ajax({
                    url: "<?php echo e(url('admin/admin_del')); ?>",
                    type: 'post',
                    data: {id: id},
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 1) {
                            layer.msg(code.msg,
                                {
                                    icon: 5,
                                    time: 2000
                                }, function () {
                                    location.href = data.url;
                                }
                            )
                        } else {
                            layer.open({
                                icon: 6,
                                title: '失败',
                                content: data.msg,
                                anim: 6
                            })
                        }
                    }
                })
            });
            return false;
        }
    );
</script>
</body>
<!--  /Body -->
</html>
